<?php
/**
 * Template Name: New Post
 *
 * @GramediaWritingProject
 * @version 1.0
 * @Epifana & Vincentia
 */


get_header(); 

if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) ) {

	// Do some minor form validation to make sure there is content
	if (isset ($_POST['title'])) {
		$title =  $_POST['title'];
	} else {
		echo 'Please enter the wine name';
	}
	if (isset ($_POST['description'])) {
		$description = $_POST['description'];
	} else {
		echo 'Please enter some notes';
	}

	$tags = $_POST['post_tags'];
if ($_POST['action']=='draft_post'){
	// ADD THE FORM INPUT TO $new_post ARRAY
	$new_post = array(
	'post_title'	=>	$title,
	'post_content'	=>	$description,
	'post_category'	=>	array($_POST['cat']),  // Usable for custom taxonomies too
	'tags_input'	=>	array($tags),
	'post_status'	=>	'draft',           // Choose: publish, preview, future, draft, etc.
	'post_type'	=>	'post'  //'post',page' or use a custom post type if you want to
	);

	//SAVE THE POST
	$pid = wp_insert_post($new_post);

             //SET OUR TAGS UP PROPERLY
	wp_set_post_tags($pid, $_POST['post_tags']);
}
if ($_POST['action2']=='publish_post'){

	// ADD THE FORM INPUT TO $new_post ARRAY
	$new_post = array(
	'post_title'	=>	$title,
	'post_content'	=>	$description,
	'post_category'	=>	array($_POST['cat']),  // Usable for custom taxonomies too
	'tags_input'	=>	array($tags),
	'post_status'	=>	'publish',           // Choose: publish, preview, future, draft, etc.
	'post_type'	=>	'post'  //'post',page' or use a custom post type if you want to
	);

	//SAVE THE POST
	$pid = wp_insert_post($new_post);

             //SET OUR TAGS UP PROPERLY
	wp_set_post_tags($pid, $_POST['post_tags']);
}
	//REDIRECT TO THE NEW POST ON SAVE
	$link = get_permalink( $pid );
	wp_redirect( $link );

} // END THE IF STATEMENT THAT STARTED THE WHOLE FORM

//POST THE POST YO
do_action('wp_insert_post', 'wp_insert_post');


?>

    <div class="col-md-12 column content">
	<div class="row clearfix">
		
		<?php get_template_part( 'kolompertama' ); ?>
	
        
		<div class="col-md-9 column" > <!-- untuk kolom kedua yang dibagi 2 -->
		<div class="row clearfix">
				<div class="col-md-12 column">
                	<h8 class="judulprofil">Tulis Cerita</h8>
                    <br/>
                    <br/>
					<form id="new_post" name="new_post" method="post" action="" enctype="multipart/form-data">
                    <div>
                    
                    <div class="list-group-item" style="border-left:none; border-right:none;">
                        <div class="row">
                        <div class="col-md-2">Judul Cerita</div>
                            <div class="col-md-9 ">
                                <div class="col-sm-12">
                                    <input class="form-control tinggitextbox" id="title" type="text" name="title" placeholder="Judul Cerita Wajib diisi">
									
                                </div>
                            </div>
                        </div>
                    	</div>
                    <div class="list-group-item" style="border-left:none; border-right:none;">
                        <div class="row">
                        <div class="col-md-2">Kategori</div>
                            <div class="col-md-9 ">
                                <div class="dropdown padd5">
								<?php wp_dropdown_categories( 'show_option_none=Silakan Pilih Kategori&tab_index=10&taxonomy=category&hide_empty=0&class="btn btn-default dropdown-toggle"&' ); ?>
                                  </div>
                            </div>
                        </div>
                    </div>
                    <br/>
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <div class="btn-group">
                              <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-align-right"></span></button>
                              <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-align-center"></span></button>
                              <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-align-justify"></span></button>
                              <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-align-left"></span></button>
                              <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-text-height"></span></button>
                              <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-bold"></span></button>
                              <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-italic"></span></button>
                              <div class="btn-group">
                                  <button class="btn btn-default btn-xs dropdown-toggle" type="button" data-toggle="dropdown">
                                    Times New Roman <span class="caret"></span>
                                  </button>
                                      <ul class="dropdown-menu" role="menu">
                                        <li><a href="#" style="background-color:#FFFFFF; border-bottom:#CCCCCC thin dotted; color:#333333">Calibri</a></li>
                                        <li><a href="#" style="background-color:#FFFFFF; border-bottom:#CCCCCC thin dotted; color:#333333">Arial</a></li>
                                        <li><a href="#" style="background-color:#FFFFFF; border-bottom:#CCCCCC thin dotted; color:#333333">San Serif</a></li>
                                      </ul>
                              </div>
                              <div class="btn-group">
                                  <button class="btn btn-default btn-xs dropdown-toggle" type="button" data-toggle="dropdown">
                                    10px <span class="caret"></span>
                                  </button>
                                      <ul class="dropdown-menu" role="menu">
                                        <li><a href="#" style="background-color:#FFFFFF; border-bottom:#CCCCCC thin dotted; color:#333333">12px</a></li>
                                        <li><a href="#" style="background-color:#FFFFFF; border-bottom:#CCCCCC thin dotted; color:#333333">14px</a></li>
                                        <li><a href="#" style="background-color:#FFFFFF; border-bottom:#CCCCCC thin dotted; color:#333333">16px</a></li>
                                      </ul>
                              </div>
                              
                              </div>
                        </div>
                        <textarea class="kotaktext" name="description" id="description">
                        
                        </textarea>
                        </div>
                        
                       <div class="row">
                        
                        <div class="col-xs-6">
                            <div class="row">
                                <div class="col-xs-10 padd6">
                                <div class="input-group input-group-sm">
                                  <span class="input-group-addon">Upload Cover</span>
                                  <input type="text" class="form-control" placeholder="Browse untuk upload cover cerita">
                                </div>
                                </div>
                                <button type="button" class="btn btn-default tombolcari tinggitextbox"><span class="glyphicon glyphicon-search"></span></button>
                           </div>
                       </div>
                       <div class="col-xs-6">
                       <div class="row">
                            <div class="col-xs-10 padd6">
                            <div class="input-group input-group-sm">
                              <span class="input-group-addon">Upload Gambar</span>
                              <input type="text" class="form-control" placeholder="Browse untuk upload gambar ilustrasi cerita" />
                            </div>
                            </div>
                            <button type="button" class="btn btn-default tombolcari tinggitextbox tooltip-bottom" data-tooltip="cari"><span class="glyphicon glyphicon-search"></span></button>
                       </div>
                       </div>
                       </div>
                    </div>
                    <br/>
                    <div class="row">
                        <div class="col-xs-6">
                            <div class="input-group input-group-sm padd6">
                                <span class="input-group-addon"><span class="glyphicon glyphicon-tags"></span></span>
                                <input type="text" class="form-control" name="post_tags" id="post_tags" placeholder="pisahkan tag dengan tanda ',' atau ';'" />
                            </div>
                        </div>
                    </div>
                    <br/>
					<input type="submit" value="Simpan Draft" tabindex="40" id="submit" name="submit" class="btn btn-sm">
	   				<input type="hidden" name="action" value="draft_post" /></input>
					
					<input type="submit" value="Simpan dan Publish" tabindex="40" id="submit" name="submit" class="btn btn-sm">
	   				<input type="hidden" name="action2" value="publish_post" /></input>
					<?php wp_nonce_field( 'new-post' ); ?>
                  
                    <button type="submit" class="btn btn-sm">Batal</button>
					</form>
                    </div>
                
			
       </div>      
	   </div>   	
       </div><!-- end row clearfix -->
</div> <!--end col-md-12 column content-->
	<!-- end untuk content -->
     <!-- untuk iklan -->
	<div class="row clearfix">
	<?php dynamic_sidebar('sidebar_iklan_samping')?>
		
	</div>
    
    <!-- untuk footer -->
	<?php
get_footer();
?>